package com.nantian.logic.controller.mainControl.placeControl;

import com.cuit.springboot.gdao.place.PlaceMapper;
import com.cuit.springboot.gdao.university.UniversityAreaMapper;
import com.cuit.springboot.gentry.place.Place;
import com.cuit.springboot.gentry.university.UniversityArea;
import com.nantian.logic.utils.UniversalResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value="/place")
public class placeController {

    @Autowired PlaceMapper placeMapper;
    @Autowired
    UniversityAreaMapper universityAreaMapper;

    @PostMapping(value="/selcity")
    public UniversalResult PlaceSelect(){
        List<Place> list=placeMapper.selectAllByProCity();
        return new UniversalResult(UniversalResult.SUCCESS,"123",list);
    }

    @PostMapping(value="/selarea")
    public UniversalResult<List<UniversityArea>> areaSelect(@RequestBody UniversityArea uniarea){
        List<UniversityArea> list=universityAreaMapper.selectByUniversityId(uniarea.getUniversityid());
        return new UniversalResult<List<UniversityArea>>(UniversalResult.SUCCESS,"ok",list);
    }

    @PostMapping(value="/addarea")
    public UniversalResult<List<UniversityArea>> AddArea(@RequestBody UniversityArea uniarea){
        int result=universityAreaMapper.insert(uniarea);
        /*
         *插入新的校区完成后,还需要查询id返回客户端
         */
        List<UniversityArea> list=universityAreaMapper.selectByUniversityId(uniarea.getUniversityid());
        return new UniversalResult<List<UniversityArea>>(UniversalResult.SUCCESS,"ok",list);
    }
}
